import jwt

class JWTE:
    def __init__(self):
        self.secrite_key = 'asfsdf&*&*^^&____!!!@#sfgte24fwfre'

    #加密
    def jwt_en(self,data):
        return jwt.encode(data,self.secrite_key,algorithm='HS256')
    #对比
    def jwt_check(self,token):      
        try:
            payload = jwt.decode(token,self.secrite_key,algorithms='HS256')
            newtoken = jwt.encode(payload,self.secrite_key,algorithm='HS256')
          
            if newtoken == token:
                return True
        except :
            return False

    #解密
    def jwt_de(self,token):
        try:
             payload = jwt.decode(token,self.secrite_key,algorithms='HS256')
             return payload
        except :
            return None

       
    

# import time
myjwt = JWTE()
# data = {"data": {"name": "zs", "userid": 1}}
# token = myjwt.jwt_en(data)
# print(token)

# res = myjwt.jwt_de(token)
# print(res)
